const ws = new WebSocket("ws://127.0.0.1:8000")//连接websocket服务端

//上线
ws.onopen = () => {
    ws.send("我上线啦")
}

//发送消息
ws.onmessage = (msg) =>{
    console.log(msg);
    //js原生语法从页面DOM对象中动态获取说话的内容
    const content = document.getElementById("content")
    content.innerHTML += msg.data + "<br>"
}

//报错
ws.onerror = (err) => {
    console.log(err)
}

//下线
ws.onclose = () => {
     console.log("close")
}